package cn.rokhdelar.ams.business.biz.project.service.impl;

import cn.hutool.core.lang.Assert;
import cn.rokhdelar.ams.business.biz.project.domain.po.BizProjectInfo;
import cn.rokhdelar.ams.business.biz.project.mapper.BizProjectInfoMapper;
import cn.rokhdelar.ams.business.biz.project.service.BizProjectInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author 范书铭
 * @date 2025年07月14日 14:21
 */
@Service
public class BizProjectInfoServiceImpl extends ServiceImpl<BizProjectInfoMapper, BizProjectInfo> implements BizProjectInfoService {

    /**
     * 分页查询项目信息
     */
    @Override
    public Page<BizProjectInfo> getPage(Integer pageNum, Integer pageSize, String projectName, String projectCategory) {
        Page<BizProjectInfo> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<BizProjectInfo> queryWrapper = new LambdaQueryWrapper<>();
        // 构建查询条件
        queryWrapper.like(projectName != null && !projectName.isEmpty(), BizProjectInfo::getProjectName, projectName);
        queryWrapper.eq(projectCategory != null && !projectCategory.isEmpty(), BizProjectInfo::getProjectCategory, projectCategory);
        // 按创建时间降序排序
        queryWrapper.orderByDesc(BizProjectInfo::getCreateTime);
        return baseMapper.selectPage(page, queryWrapper);
    }

    @Override
    public BizProjectInfo addProjectByCompany(BizProjectInfo bizProjectInfo) {

        save(bizProjectInfo);
        return bizProjectInfo;
    }

    @Override
    public BizProjectInfo findProjectByCode(String projectCode) {
        LambdaQueryWrapper<BizProjectInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BizProjectInfo::getProjectCode, projectCode);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public void updateStatus(String projcetCode, int status) {
        LambdaUpdateWrapper<BizProjectInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(BizProjectInfo::getProjectCode, projcetCode);
        lambdaUpdateWrapper.set(BizProjectInfo::getNowStatus,status);
        baseMapper.update(lambdaUpdateWrapper);
    }

}
    